package com.hnucm.springboot.controller;

import com.hnucm.springboot.pojo.Person;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
public class TestController {
    @RequestMapping("getperson")
    @ResponseBody
    public Person getperson(){
        Person person=new Person();
        person.setId(1);
        person.setAge(13);
        person.setName("me12345678912345678");
        return person;
    }
    @RequestMapping("getpng")
    public String getpng(Model model){
        //  png   文本  音视频  可以访问
        // jsp文件 浏览器端不能识别
        //html 浏览器端能识别
        model.addAttribute("name","Testname");
        List<Person> personList=new ArrayList<>();
        for (int i=0;i<10;i++){
            Person person=new Person();
            person.setId(i+1);
            person.setAge(21);
            person.setName("Testname:"+i);
            personList.add(person);
        }
        model.addAttribute("personList",personList);
        return "test.html";
    }
    @RequestMapping("login")
    public String login(){

        return "login.html";
    }
    @RequestMapping("logincommit")
    public String logincommit(String username,String password) {

        if (username.equals("admin") && password.equals("123456")) {
            return "success.html";
        }
        return "fail.html";
    }
    @RequestMapping("user")
    public String user() {
        return "user.html";
    }
    @RequestMapping("admin")
    public String admin() {
        return "admin.html";
    }
    @RequestMapping("mylogout")
    public String mylogout() {
        return "mylogout.html";
    }

}
